<template>
  <div class="import-content">
    <div>
      <div class="import-btn">
        <el-button v-if="fileImpParam.fileimportid" @click="changeModel">修改模板</el-button>
        <el-button v-if="!fileImpParam.fileimportid" @click="addModel">新增模板</el-button>
        <el-button @click="importReqSample">导入</el-button>
        <el-button @click="closeReqImport">取消</el-button>
      </div>
      <div class="import-info">
        <div class="import-param">
          <div class="search-title" style="width: 48px">导入模板</div>
          <div>
            <el-select v-model="fileImpParam.fileimportid" placeholder="请选择模板" clearable @change="changeFileimport"
              style="width: 130px">
              <el-option v-for="(item, index) in fileImportList" :key="index" :value="item.fileimportid"
                :label="item.fileimportname"></el-option>
            </el-select>
          </div>
          <div class="search-title">数据起始行</div>
          <div>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.startrow" disabled></el-input>
          </div>
          <div class="search-title" style="width: 62px">对应方式</div>
          <div>
            <!-- <el-input size="small" style="width:130px;" v-model="fileImpParam.coltype" disabled></el-input> -->
            <el-select v-model="fileImpParam.coltype" disabled style="width: 130px">
              <el-option label="按顺序对应" value="0"></el-option>
              <el-option label="按名称对应" value="1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="import-param">
          <div class="search-title" style="width: 48px">备注</div>
          <div style="width: calc(100% - 53px)">
            <el-input size="small" style="width: 100%" v-model="fileImpParam.note" disabled></el-input>
          </div>
        </div>
      </div>
      <div class="import-info">
        <span class="model-text" style="width: 48px">文件</span>
        <el-input class="input-upload" size="small" v-model="filename" disabled></el-input>
        <el-button icon="el-icon-files" @click="importExcel" ref="importFile">选择文件</el-button>
        <div class="upload-button">
          <el-upload ref="upload" :action="url" accept=".xls,.xlsx" :before-upload="beforeUploadFile"
            :on-change="fileChange" :show-file-list="showFile" :auto-upload="false">
            <el-button size="small" plain>选择文件</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传DAT(*dat)文件，且不超过10M</div> -->
          </el-upload>
        </div>
      </div>
      <div class="import-param">
        <div class="search-title" style="width: 85px">录入起始标本号</div>
        <div style="width: calc(100% - 90px)">
          <el-input size="small" style="width: 100%" v-model="startsampleno"></el-input>
        </div>
      </div>
    </div>
    <el-dialog width="auto" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="文件导入模板"
      v-if="modelSetDialog" :visible.sync="modelSetDialog" @closed="closeModelSet">
      <div class="modelset-content">
        <div class="modelset-left">
          <div class="model-param">
            <span class="model-text">导入模板ID</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.fileimportid" disabled></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">导入目标</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.importdest" disabled></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">模板名称</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.fileimportname"></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">文件类型</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.filetype" disabled></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">数据起始行</span>
            <el-input type="number" min="0" size="small" style="width: 130px" v-model="fileImpParam.startrow"></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">对应方式</span>
            <el-select v-model="fileImpParam.coltype" placeholder="请选择对应方式" style="width: 130px">
              <el-option label="按顺序对应" value="0"></el-option>
              <el-option label="按名称对应" value="1"></el-option>
            </el-select>
          </div>
          <div class="model-param">
            <span class="model-text">所属医院</span>
            <rm-ddl-common datatype="hospital" v-model="fileImpParam.hospcode" style="display: inline-block"
              width="130px"></rm-ddl-common>
          </div>
          <div class="model-param">
            <span class="model-text">创建人</span>
            <rm-ddl-common v-model="fileImpParam.create_user" datatype="doctor" style="display: inline-block"
              width="130px" disabled></rm-ddl-common>
          </div>
          <div class="model-param">
            <span class="model-text">创建时间</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.create_dt" disabled></el-input>
          </div>
          <div class="model-param">
            <span class="model-text">备注</span>
            <el-input size="small" style="width: 130px" v-model="fileImpParam.note"></el-input>
          </div>
          <div class="model-param" style="color: #1476a5">
            <div>1、选择导入文件，再填写模板名称、起始行、对应方式。</div>
            <div>2、在右侧进行列对应，如果已经选择过文件，则可以直接下拉文件列名称进行对照</div>
            <div>3、所有字段都应是代码，程序不会根据名称转换代码</div>
            <div>4、文件中不存在的列可以填写默认值</div>
            <div>5、主表唯一标识一定要选，也就是勾选主表的一个列相同就认定为一个申请单。比如勾选条码号。报告导入不需要</div>
            <div>6、还有其它选项在“选项”页面设置，可以设詈生成新条码号，重新分单，手工追加申请项目等等</div>
          </div>
        </div>
        <div class="modelset-right">
          <el-tabs v-model="setFileName" @tab-click="handleTabClick" type="card">
            <el-tab-pane label="对应列" name="importDet">
              <div class="eltab-content">
                <vxe-table ref="detTable" :data.sync="detList" class="mytable-style" height="auto" border size="mini"
                  resizable stripe :sort-config="{ trigger: 'cell' }" show-overflow highlight-current-row
                  header-align="center"
                  :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }">
                  <vxe-table-column field="datacol" sortable title="对应数据列" width="170">
                    <template v-slot="{ row }">
                      <span>{{ row.datacolcn }}</span>
                      <span>[{{ row.datacol }}]</span>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="filecolseq" sortable title="文件列序号" width="70"
                    :edit-render="{ name: 'input', autoselect: true }">
                    <template v-slot:edit="{ row }">
                      <el-select v-model="row.filecolseq" placeholder="" filterable remote
                        :remote-method="fillterDetTableseq" @focus="clearFilter" @change="filecolseqChange($event, row)"
                        allow-create default-first-option clearable :popper-append-to-body="false"
                        popper-class="mini-select" style="width: 100%">
                        <el-option v-for="(item, index) in detTableseq" :key="index" :label="item"
                          :value="item"></el-option>
                      </el-select>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="filecolname" sortable title="文件列名称" width="110"
                    :edit-render="{ name: 'input', autoselect: true }">
                    <template v-slot:edit="{ row }">
                      <!-- <el-input v-model="row.filecolname"></el-input> -->
                      <el-select v-model="row.filecolname" placeholder="" filterable remote
                        :remote-method="fillterDetTableTitle" @focus="clearFilter"
                        @change="filecolnameChange($event, row)" allow-create default-first-option clearable
                        :popper-append-to-body="false" popper-class="mini-select" style="width: 100%">
                        <el-option v-for="(item, index) in detTableTitle" :key="index" :label="item"
                          :value="item"></el-option>
                      </el-select>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="defaultval" sortable title="默认值" width="115"
                    :edit-render="{ name: 'input', autoselect: true }">
                    <template v-slot:edit="{ row }">
                      <el-input v-model="row.defaultval" @change="updateFdetList($event, row, 'defaultval')"></el-input>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="masterkey" sortable title="主表唯一标识" width="55" align="center">
                    <template v-slot="{ row }">
                      <el-checkbox v-model="row.masterkey" true-label="1" false-label="0"
                        @change="updateFdetList($event, row, 'masterkey')"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="fileimportid" sortable title="文件导入模板ID" width="55"
                    align="center"></vxe-table-column>
                  <vxe-table-column field="datacoltype" sortable title="数据类型" width="60"></vxe-table-column>
                  <vxe-table-column field="seq" title="序号" width="40" align="center"></vxe-table-column>
                </vxe-table>
              </div>
            </el-tab-pane>
            <el-tab-pane label="默认值" name="importOption">
              <div class="eltab-content">
                <vxe-table ref="optionTable" :data.sync="optionList" class="mytable-style" height="auto" border
                  size="mini" resizable stripe :sort-config="{ trigger: 'cell' }" show-overflow highlight-current-row
                  header-align="center"
                  :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: true }">
                  <vxe-table-column field="optioncode" sortable title="选项代码" width="130"></vxe-table-column>
                  <vxe-table-column field="optionname" sortable title="选项名称" width="200 "></vxe-table-column>
                  <vxe-table-column field="optionvalue" sortable title="取值" width="80"
                    :edit-render="{ name: 'input', autoselect: true }">
                    <template v-slot:edit="{ row }">
                      <el-input type="number" min="0" v-model="row.optionvalue"></el-input>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="note" sortable title="说明" width="155"></vxe-table-column>
                  <vxe-table-column field="optionkind" sortable title="选项类别" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="fileimportid" sortable title="文件导入模板ID" width="55"
                    align="center"></vxe-table-column>
                </vxe-table>
              </div>
            </el-tab-pane>
          </el-tabs>
          <div class="modelset-btn">
            <el-button @click="importExcelDet">选择文件</el-button>
            <div class="upload-button">
              <el-upload ref="uploadDet" :action="url" accept=".xls,.xlsx" :before-upload="beforeUploadFile"
                :on-change="fileChangeDet" :show-file-list="showFile" :auto-upload="false">
                <el-button size="small" plain>选择文件</el-button>
                <!-- <div slot="tip" class="el-upload__tip">只能上传DAT(*dat)文件，且不超过10M</div> -->
              </el-upload>
            </div>
            <el-button @click="autoCompare" style="margin-left: 10px">智能对照</el-button>
            <el-button @click="saveSecFileImport">保存</el-button>
            <el-button @click="closeModelSet(1)">退出</el-button>
            <el-button v-if="showCompareflag" @click="showCompareData(1)">隐藏未对照</el-button>
            <el-button v-else @click="showCompareData(2)">显示未对照</el-button>
            <el-button v-if="isdelete" @click="deleteModel">删除模板</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :show-close="false" :append-to-body="true" :close-on-click-modal="false" title="文件导入结果"
      :visible.sync="dialogupload" width="350px">
      <div style="position: relative; width: 100%">
        <table style="border: 1px solid #ffffff; width: 95%; margin: auto">
          <tr>
            <td style="text-align: left; width: 50px">共:<span>{{ this.totalcnt }}</span>条</td>

            <td style="text-align: left; width: 50px">成功: <span style="color: blue">{{ this.successcnt }}</span>条</td>

            <td style="text-align: left; width: 50px">失败:<span style="color: red">{{ this.failcnt }}</span>条</td>

          </tr>
          <tr>
            <td colspan="3" style="text-align: left">{{ this.uploadmsg }}</td>
          </tr>
          <tr style="height: 50px">
            <td colspan="3" style="text-align: right">
              <el-button style="width: 80px" @click="dialog_upload">确定</el-button>
            </td>
          </tr>
        </table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
import reqitem from "@/components/common/reqitem";
import XLSX from "xlsx";
import axios from "axios";
export default {
  props: {
    prono: {
      type: String,
      default: "",
      require: true,
    },
    importdest: {
      type: String,
      default: "",
      require: true,
    },
    sampledate: {
      type: String,
      default: "",
      require: true,
    },
    rptunitid: {
      type: Number,
      default: "",
      require: true,
    },
  },
  data() {
    return {
      dialogupload: false,
      successcnt: 0,
      failcnt: 0,
      totalcnt: 0,
      uploadmsg: "",
      fileImpParam: {
        fileimportid: "",
      },
      allowaddreqitemflag: "0",
      fileImportList: [],
      showFile: false,
      url: "LIS/LIS3/" + this.prono,
      form: {},
      filename: "",
      modelSetDialog: false,
      setFileName: "importDet",
      fdetList: [],
      detList: [],
      optionList: [],
      fileoptionList: reqitem.fileimportOptionList,
      detTableData: [],
      fdetTableseq: [],
      detTableseq: [],
      fdetTableTitle: [],
      detTableTitle: [],
      showCompareflag: true,
      startsampleno: "1",
      delfileimportid: "",
      isdelete: false,
    };
  },
  mounted() {
    this.querySecfileimport();
  },
  methods: {
    querySecfileimport() {
      this.$tool
        .request({
          url: "LIS/LIS3/" + this.prono,
          method: "post",
          data: {
            action: "querysecfileimport",
            // prono: "LIS251",
          },
        })
        .then((response) => {
          this.fileImportList = response.fileimport;
          if (this.fileImportList.length > 0) {
            this.fileImpParam = this.fileImportList[0];
            this.querySecfileimportdetial(this.fileImpParam.fileimportid);
          }
        })
        .catch((e) => { });
    },
    initsecfileimportcol() {
      let response = this.$tool.request({
        url: "LIS/LIS3/" + this.prono,
        method: "post",
        data: {
          action: "initsecfileimportcol",
        },
      });
      return response;
    },
    importReqSample() {
      if (!this.form.file) return false;
      let rloading = this.$loading({
        // 声明一个loading对象
        lock: true, // 是否锁屏
        text: "开始导入数据，请稍等！", // 加载动画的文字
        spinner: "el-icon-loading", // 引入的loading图标
        background: "rgba(0, 0, 0, 0.3)", // 背景颜色
        target: ".sub-main", // 需要遮罩的区域
        body: true,
        customClass: "mask" // 遮罩层新增类名
      });
      let formData = new FormData();
      formData.append("action", "LIS310");
      formData.append("file", this.form.file);
      formData.append("sampledate", this.sampledate);
      formData.append("rptunitid", this.rptunitid);
      formData.append("fileimportid", this.fileImpParam.fileimportid);
      formData.append("sampleno", this.startsampleno);

      var URL = this.$tool.baseUrl.replace("api", "z") + "fileupload";
      axios
        .post(URL, formData, { "Content-Type": "multipart/form-data" })
        .then((res) => {
          let response = res.data;
          rloading.close();
          // console.log("rrr", res, res.data, response, response["flag"], response["msg"], response.msg);
          // console.info("rrrrrr=="+response.flag);
          if (response.flag == "1") {
            this.$alert("文件上传成功,共上传数据【" + response.cnt + "】条");
            this.closeReqImport();
          }
          else if (response.flag == "99") {
            let cnt = response.cnt.split(':');
            this.successcnt = cnt[0]
            this.failcnt = cnt[1];
            this.totalcnt = Number(cnt[0]) + Number(cnt[1]);
            this.uploadmsg = "其中" + response.msg;
            this.dialogupload = true;
            // this.$alert("文件上传成功【"+cnt[0]+"】条,失败【"+cnt[1]+"】条，其中"+response.msg);
          }
          else if (response.flag == "0") {
            this.$alert(response.msg);
            this.closeReqImport();
          }
          else {
            this.$alert("文件上传失败，具体原因查看日志");
            this.closeReqImport();
          }
          //this.closeReqImport();
          // if (response.flag == "1") {
          //     this.$notify.success({
          //         title: "成功",
          //         message: `文件上传成功`,
          //     });
          // } else {
          //     this.$notify.error({
          //         title: "错误",
          //         message: response.msg,
          //     });
          // }
        })
        .catch((e) => {
          rloading.close();
          this.$alert(e, "出错");
        });
    },
    dialog_upload() {
      this.dialogupload = false;
      this.$emit("change");
    },
    closeReqImport() {
      this.$emit("change");
    },
    changeFileimport(e) {
      if (e) {
        this.querySecfileimportdetial(e);
      } else {
        this.fileImpParam = {};
      }
    },
    querySecfileimportdetial(fileimportid) {
      this.$tool
        .request({
          url: "LIS/LIS3/" + this.prono,
          method: "post",
          data: {
            action: "querysecfileimportdetial",
            fileimportid: fileimportid,
          },
        })
        .then((response) => {
          if (response.fileimport.length > 0) {
            this.fileImpParam = response.fileimport[0];
            this.$forceUpdate();
          }
        })
        .catch((e) => { });
    },
    importExcel() {
      this.$refs["upload"].$refs["upload-inner"].handleClick();
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.filename = file.name;
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if (extension !== "xls" && extension !== "xlsx") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传xls,xlsx(*xls,*xlsx)文件，且不超过10M`,
        });
      }
      if (size > 10) {
        this.$notify.warning({
          title: "警告",
          message: `文件大小不得超过10M`,
        });
      }
    },
    fileChangeDet(file, fileList) {
      // console.log(file, fileList)
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (extension == "xls" || extension == "xlsx") {
        this.fileImpParam.filetype = "XLS";
        this.$forceUpdate();
      }
      this.file2Xce(file).then((tab) => {
        // console.log(tab)
        if (tab && tab.length > 0) {
          let xlscList = [];
          if (tab.length > 0) {
            let sheetTitle = tab[0].sheet[0]; // 此处只取第一个 sheet 的第一行数据，标题
            for (let i in sheetTitle) {
              xlscList.push({
                seq: i,
                name: sheetTitle[i],
              });
            }
          }
          // console.log(xlscList);
          this.dealTabledata(xlscList);
        }
      });
    },
    file2Xce(file) {
      return new Promise(function (resolve, reject) {
        const reader = new FileReader();
        reader.onload = function (e) {
          let data = e.target.result;
          let wb = XLSX.read(data, {
            type: "binary",
          });
          let result = [];
          wb.SheetNames.forEach((sheetName) => {
            // 多张表
            result.push({
              sheetName: sheetName,
              sheet: XLSX.utils.sheet_to_json(wb.Sheets[sheetName], { header: 1, raw: false }),
            });
          });
          resolve(result);
        };
        reader.readAsBinaryString(file.raw);
        // reader.readAsBinaryString(file) // 传统input方法
      });
    },
    dealTabledata(xlscList) {
      let num = [];
      let name = [];
      xlscList.forEach((element) => {
        element.seq = Number(element.seq) + 1;
        num.push(element.seq);
        name.push(element.name);
      });
      this.detTableData = xlscList;
      this.fdetTableseq = JSON.parse(JSON.stringify(num));
      this.detTableseq = num;
      this.fdetTableTitle = JSON.parse(JSON.stringify(name));
      this.detTableTitle = name;
    },
    autoCompare() {
      this.detList.forEach((element) => {
        let row = this.detTableData.filter((item) => item.name == element.datacol || item.name == element.datacolcn);
        if (row.length > 0) {
          // row.forEach(data => {
          //     element.filecolseq = data.seq;
          //     element.filecolname = data.name;
          // });
          element.filecolseq = row[0].seq;
          element.filecolname = row[0].name;
        }
      });
      this.fdetList = JSON.parse(JSON.stringify(this.detList));
      this.$refs.detTable.reloadData(this.detList);
    },
    saveSecFileImport() {
      if (!this.fileImpParam.fileimportname) {
        this.$pub.message(this, "模板名称不能为空！", "warning");
        return false;
      }
      let secfileimportdetList = [];
      let masterkeyflag = 0;
      this.fdetList.forEach((element) => {
        if (element.masterkey == "1") masterkeyflag++;
        if (element.filecolseq || element.filecolname || element.defaultval || element.masterkey == "1") {
          secfileimportdetList.push(element);
        }
      });
      if (masterkeyflag != 1) {
        this.$confirm("唯一标识符只能在主表选择一个字段，且必须选择一个！", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => { })
          .catch(() => { });
        return false;
      }
      this.$tool
        .request({
          url: "LIS/LIS3/" + this.prono,
          method: "post",
          data: {
            action: "savesecfileimport",
            utype: this.fileImpParam.fileimportid ? "M" : "A",
            secfileimport: this.fileImpParam,
            // secfileimportdet: this.fdetList,
            secfileimportdet: secfileimportdetList,
            secfileimportoption: this.optionList,
          },
        })
        .then((response) => {
          if (response.flag == "1") {
            this.$pub.message(this, "保存成功", "success");
          } else {
            this.$pub.message(this, response.errmsg, "warning");
          }
        })
        .catch((e) => { });
    },
    // 删除模板
    deleteModel() {
      this.$confirm("你确定删除【" + this.fileImpParam.fileimportname + "】这条模板吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$tool
          .request({
            url: "LIS/LIS3/LIS310",
            method: "post",
            data: {
              action: "deletesecfileimport",
              fileimportid: this.delfileimportid,
            },
          })
          .then((res) => {
            if (res.flag == 1) {
              this.$message.success("删除模板成功！");
              this.$emit("change");
            } else {
              this.$message.error("删除模板失败！");
            }
          })
          .catch((e) => {
            this.$alert(e);
          });
      });
    },

    closeModelSet(type) {
      if (type == 1) {
        this.modelSetDialog = false;
      }
      this.detTableData = [];
      this.fdetTableseq = [];
      this.detTableseq = [];
      this.fdetTableTitle = [];
      this.detTableTitle = [];
      this.setFileName = "importDet";
    },
    handleTabClick(tab, event) {
      this.setFileName = tab.name;
      if (tab.name == "importDet") {
        this.$refs.detTable.loadData(this.detList);
      } else if (tab.name == "importOption") {
        this.$refs.optionTable.loadData(this.optionList);
      }

    },
    showCompareData(type) {
      if (type == 1) {
        let data = this.fdetList.filter((item) => item.filecolseq || item.filecolname);
        this.detList = data;
        this.showCompareflag = false;
      } else {
        this.detList = JSON.parse(JSON.stringify(this.fdetList));
        this.showCompareflag = true;
      }
    },
    fillterDetTableseq(e) {
      let list = [];
      if (e) {
        list = this.fdetTableseq.filter((item) => item.indexOf(e) > 0);
      } else {
        list = XEUtils.clone(this.fdetTableseq, true);
      }
      this.detTableseq = list;
    },
    clearFilter() {
      this.detTableseq = JSON.parse(JSON.stringify(this.fdetTableseq));
      this.detTableTitle = JSON.parse(JSON.stringify(this.fdetTableTitle));
    },
    filecolseqChange(e, row) {
      row.filecolseq = e;
      this.updateFdetList(e, row, "filecolseq");
    },
    fillterDetTableTitle(e) {
      let list = [];
      if (e) {
        list = this.fdetTableseq.filter((item) => item.indexOf(e) > 0);
      } else {
        list = XEUtils.clone(this.fdetTableTitle, true);
      }
      // cb(list);
      this.detTableTitle = list;
    },
    filecolnameChange(e, row) {
      row.filecolname = e;
      this.updateFdetList(e, row, "filecolname");
    },
    updateFdetList(value, row, colname) {
      this.fdetList.forEach((element) => {
        if (element.datacol == row.datacol) {
          element[colname] = value;
        }
      });
    },
    changeModel() {
      var that = this;
      that.isdelete = true;
      that.delfileimportid = that.fileImpParam.fileimportid;

      that.modelSetDialog = true;
      that.initsecfileimportcol().then((res) => {
        that.$tool
          .request({
            url: "LIS/LIS3/" + that.prono,
            method: "post",
            data: {
              action: "queryfiledetial",
              fileimportid: that.fileImpParam.fileimportid,
            },
          })
          .then((response) => {
            if (response.flag == "1") {
              if (response.fileimport.length > 0) {
                that.fileImpParam = response.fileimport[0];
              }
              // 处理 Sec_FileImportDet 表对应列字段
              if (response.fileimportdet.length > 0) {
                let list = res.filedetlist;
                list.forEach((element) => {
                  element.fileimportid = that.fileImpParam.fileimportid;
                  let row = response.fileimportdet.find((item) => item.datacol == element.datacol);
                  if (row) {
                    element.filecolseq = row.filecolseq;
                    element.filecolname = row.filecolname;
                    element.defaultval = row.defaultval;
                    element.masterkey = row.masterkey;
                  }
                });
                that.fdetList = JSON.parse(JSON.stringify(list));
                that.detList = list;
              } else {
                that.fdetList = JSON.parse(JSON.stringify(res.filedetlist));
                that.detList = res.filedetlist;
              }
              // if(response.fileimportoption.length>0){
              //     let list=reqitem.fileimportOptionList;
              //     list.forEach((element)=>{
              //         element.fileimportid=that.fileImpParam.fileimportid;
              //         let row=response.fileimportoption.find((item)=> item.optioncode == element.optioncode);
              //         if(row){
              //             element.optionvalue=row.optionvalue;
              //         }
              //     })
              // }
              //目前默认值只有一条，若默认值有多个，需要调整这里
              if (response.fileimportoption.length > 0) {
                that.optionList = response.fileimportoption;
              } else {
                let list = reqitem.fileimportOptionList;
                list.forEach((element) => {
                  element.fileimportid = that.fileImpParam.fileimportid;
                })
                that.optionList = list;
              }

            } else {
              that.$pub.message(that, response.errmsg, "warning");
            }
          })
          .catch((e) => { });
      });
    },
    addModel() {
      this.initsecfileimportcol().then((response) => {
        this.fdetList = JSON.parse(JSON.stringify(response.filedetlist));
        this.detList = response.filedetlist;
      });
      this.optionList = reqitem.fileimportOptionList;
      this.modelSetDialog = true;
      this.isdelete = false;
      this.fileImpParam = {};
      this.fileImpParam.importdest = "RPT";
      this.fileImpParam.hospcode = "All";
    },
    importExcelDet() {
      this.$refs["uploadDet"].$refs["upload-inner"].handleClick();
    },
  },
};
</script>

<style scoped>
.import-content {
  color: #000000;
  font-size: 12px;
}

.import-btn {
  text-align: right;
  /* margin: 0 0 10px 0; */
}

.import-info {
  margin: 0 0 5px 0;
}

.import-param {
  display: flex;
  margin: 5px 0;
}

.search-title {
  width: 75px;
  margin: 0 5px 0 0;
  text-align: right;
  line-height: 26px;
}

.input-upload {
  width: calc(100% - 153px);
  margin-right: 5px;
}

.upload-button {
  height: 24px;
  margin: 0 10px;
  display: none;
}

.upload-button div {
  height: 24px;
}

.reqitem-content {
  display: flex;
  height: 250px;
}

.reqitem-table {
  width: 490px;
  height: 220px;
}

.reqitem-table table {
  height: 100%;
}

.reqitem-btn {
  text-align: center;
  margin: auto 0 auto auto;
}

.reqitem-btn div {
  margin: 15px 0;
}

::v-deep .reqitem-btn .el-button {
  width: 90px;
}

.modelset-content {
  display: flex;
  color: #000000;
  font-size: 12px;
}

.modelset-left {
  width: 205px;
}

.model-param {
  margin: 3px 0;
}

.model-text {
  width: 70px;
  margin: 0 5px 0 0;
  text-align: right;
  display: inline-block;
}

.modelset-right {
  width: 710px;
  height: 506px;
  margin-left: 10px;
}

::v-deep .modelset-right .el-tabs {
  height: calc(100% - 35px);
}

::v-deep .modelset-right .el-tabs__header {
  margin: 0 0 5px !important;
}

::v-deep .modelset-right .el-tabs__content {
  position: relative !important;
  top: 0 !important;
  height: calc(100% - 33px);
}

.eltab-content,
.eltab-content table,
.mytable-style {
  height: 100%;
}

::v-deep .eltab-content .vxe-table .vxe-header--column {
  line-height: 19px !important;
}

.modelset-btn {
  margin: 5px 0;
  text-align: center;
}

::v-deep .el-input.is-disabled .el-input__inner {
  color: #000000 !important;
}</style>
